package com.minmin.testCases;

import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;

@Slf4j
public class TestStaff extends TestCom {

    public TestStaff(WebDriver driver) {
        super(driver);
    }

    public void testStaff() throws InterruptedException {
        log.info("进入人员管理模块");
        eXpath("//span[text()=\"人员\"]").click();

        log.info("进入员工管理模块");
        eXpath("//span[text()=\"员工管理\"]").click();
        testEmployee();
        log.info("--------------------------------------------");
        Thread.sleep(500);

        log.info("进入部门管理模块");
        eXpath("//span[text()=\"部门管理\"]").click();
        testDepartment();
        log.info("--------------------------------------------");
        Thread.sleep(500);
    }

    private void testDepartment() throws InterruptedException {
        Thread.sleep(300);
        log.info("创建部门");
        eXpath("//button/span[\"添加部门\"]").click();
        eXpath("//input[@placeholder=\"请输入\"]").sendKeys("零食部");
        eXpath("//button/span[text()=\"确认\"]").click();
        if (A.alert(driver, "操作成功")) {
            log.info("创建部门成功");
        } else {
            log.info("创建部门失败");
        }
        log.info("删除部门");
        Thread.sleep(500);
        eXpath("(//button/span[text()=\" 删除 \"])[1]").click();
        eXpath("//button/span[text()=\"确定\"]").click();
        if (A.alert(driver, "操作成功")) {
            log.info("删除部门成功");
        } else {
            log.info("删除部门失败");
        }
    }

    private void testEmployee() {
        log.info("新增员工");
        eXpath("//button/span[text()=\"新增用户\"]").click();
        eXpath("(//input[@placeholder=\"请输入登录账号\"])[1]").sendKeys("自动新增员工");
        eXpath("//input[@placeholder=\"请输入姓名\"]").sendKeys("自动新增员工");
        eXpath("(//input[@placeholder=\"请输入手机号\"])[2]").sendKeys("16888888888");
        eXpath("//input[@placeholder=\"请输入密码\"]").sendKeys("123456");
        eXpath("(//input[@placeholder=\"请选择分配角色\"])[1]").click();
        actions.sendKeys(Keys.DOWN).perform();
        actions.sendKeys(Keys.ENTER).perform();

        if (A.alert(driver, "操作成功")) {
            log.info("新增员工成功");
        } else {
            log.info("新增员工失败");
            return;
        }

        log.info("删除员工");
        eXpath("(//button/span[text()=\"离职\"])[1]").click();
        eXpath("//button/span[text()=\"确定\"]").click();
        if (A.alert(driver, "操作成功")) {
            log.info("删除员工成功");
        } else {
            log.info("删除员工失败");
        }
    }
}
